<template>
	<view class="wrapper">
		<view class="title">热卖配件</view>
		<view class="list">
			<view class="item" v-for="item in dataSource.list" :key="item._id" @click="goDetailPage(item)">
				<view class="img">
					<image :src="IMG_URL + item.goodsImg" mode="aspectFill"></image>
				</view>
				<view class="info">
					<view class="hd">{{ item.goodsName }}</view>
					<view class></view>
					<view class="price">￥{{ item.goodsPrice }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		reactive
	} from "vue"
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		IMG_URL,
		BASE_URL
	} from "@/config/index.js"

	const dataSource = reactive({
		list: []
	})

	const getList = () => {
		uni.request({
			url: `${BASE_URL}goodslist`,
			data: {
				type: 1 // 1:为车;2:配件
			},
			success: res => {
				const {
					data
				} = res.data
				dataSource.list = [.data]
			}
		});
	}

	const goDetailPage = (item) => {
		uni.navigateTo({
			url: '/pages/otherPages/detail?id=' + item._id
		})
	}

	onLoad(() => {
		getList()
	})
</script>

<style lang="scss" scoped>
	.title {
		font-weight: bold;
		font-size: 36rpx;
		padding: 20rpx 15rpx;
		text-align: center;
		color: #a90738;
		margin: 10rpx 0;
		background: #fff;
		border-bottom: 1rpx solid #efefef;
	}

	.item {
		display: flex;
		align-items: flex-start;
		border-bottom: 1rpx solid #efefef;
		padding-bottom: 20rpx;
		margin-bottom: 20rpx;
		box-sizing: border-box;

		.img {
			width: 320rpx;
			height: 240rpx;
			overflow: hidden;
			background-color: #fff;
			box-sizing: border-box;

			image {
				width: 100%;
				height: 100% !important;

			}
		}

		.info {
			padding-left: 20rpx;

			.hd {
				font-size: 38rpx;
			}

			.price {
				margin-top: 20rpx;
				color: #a90738;
				font-weight: bold;
				font-size: 34rpx;
			}
		}
	}
</style>